package action;



import java.util.ArrayList;
import java.util.Map;
import models.DeveloperData;
import models.IssueData;
import models.TagData;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AssignAction  {
	private static final Object TagList = null;
	Map<String, Object> session;
	private String assignbutton;
	private String dev_select;
	private int priority_selected;
	ArrayList<models.DeveloperData> DeveloperList=new ArrayList<models.DeveloperData>();
	
	public ArrayList<models.DeveloperData> getDeveloperList() {
			return DeveloperList;
		}
		public void setDeveloperList(ArrayList<models.DeveloperData> developerList) {
			DeveloperList = developerList;
		}
	public String execute(){
		if(assignbutton.startsWith("claim issue"))
		{
		session = ActionContext.getContext().getSession();
		IssueData issue = (IssueData)session.get("Issue");
		DeveloperData developer = (DeveloperData)session.get("Developer");
		IssueData issue_insert = new IssueData();
		issue_insert.setAssignedto(developer.getDevelopername());
		issue_insert.setIssue_num(issue.getIssue_num());
		issue_insert.setIssue_status("assigned");
		issue_insert.setIssue_priority(priority_selected);
		issue_insert.setDev_id(0);
		issue_insert.updateIssueAssign("");
	//	TagList=TagData.tag_name_unique("");
    	//for(int i=0;i<TagList.size();i++){
    		//TagNamesList.add(TagList.get(i).getTagName());}
		ArrayList<IssueData> IssueList = IssueData.find("");
    	System.out.println("inlogacc  "+IssueList.get(0).getAssignedto());
    	//session.put("TagList", TagList );
    	session.put("IssueList",IssueList);
		return "success";
		}
		else if(assignbutton.startsWith("assign issue"))
		{
			System.out.println("dev_sel"+dev_select);
			if(dev_select.equalsIgnoreCase("-1"))
			{
				// addActionError(getText("Incorrect user id and / or password!"));
				return "error";
				
			}
			
			session = ActionContext.getContext().getSession();
			IssueData issue = (IssueData)session.get("Issue");
		//	DeveloperData developer = (DeveloperData)session.get("Developer");
			IssueData issue_insert = new IssueData();
			issue_insert.setAssignedto(dev_select);
			issue_insert.setIssue_num(issue.getIssue_num());
			issue_insert.setDev_id(0);
			issue_insert.setIssue_status("assigned");
			issue_insert.setIssue_priority(priority_selected);
			issue_insert.updateIssueAssign("");
			System.out.println("in admin");
			ArrayList<IssueData> IssueList = IssueData.find("");
	    	System.out.println("inlogacc  "+IssueList.get(0).getAssignedto());
	    	//session.put("TagList", TagList );
	    	session.put("IssueList",IssueList);
			return "success";
		}
		return "success";
	}
	public String getAssignbutton() {
		return assignbutton;
	}
	public void setAssignbutton(String assignbutton) {
		this.assignbutton = assignbutton;
	}
	public String getDev_select() {
		return dev_select;
	}
	public void setDev_select(String dev_select) {
		this.dev_select = dev_select;
	}
	public int getPriority_selected() {
		return priority_selected;
	}
	public void setPriority_selected(int priority_selected) {
		this.priority_selected = priority_selected;
	}

}
